package com.jswlw.controller.distributor;

import com.jswlw.controller.BaseController;
import com.jswlw.entity.biz.BookInfo;
import com.jswlw.service.biz.BookInfoService;
import com.jswlw.web.manager.SessionDistributorManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Controller
@RequestMapping("/distributor/book")
public class DistributorBookController extends BaseController{

    @Autowired
    BookInfoService bookInfoService;

    @RequestMapping("index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/distributor/book/index");
        BookInfo filter = new BookInfo();
        filter.setDistributorIds(SessionDistributorManager.getCurrentUser().getChildrenIds());
        modelAndView.addObject("bookList", bookInfoService.queryList(filter));
        return modelAndView;
    }

    /**
     * 删除广告
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/deal")
    @ResponseBody
    public ModelMap deal(Model model, Integer id) {
        try {
            BookInfo bookInfo = new BookInfo();
            bookInfo.setId(id);
            bookInfo.setStatus(1);
            bookInfoService.update(bookInfo);
            return this.successResult("处理成功");
        } catch (Exception e) {
            logger.error("处理失败", e);
            return this.failResult("处理失败" + e.getMessage());
        }
    }
}
